<?php
/**
 * Created by PhpStorm.
 * Script Name: MiniCategory.php
 * Create: 2023/2/6 15:56
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\service;


use EasyOpen\Tencent\Request\Mp\WxaGetCategory;
use EasyOpen\Tencent\Request\Mp\WxOpenDeleteCategory;
use EasyOpen\Tencent\Request\Mp\WxOpenGetCategory;

class MiniCategory extends Mini
{
    /**
     * 提交审核可用类目
     * @param null $mini_info
     * @return mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function auditCategoryGet($mini_info = null){
        $request = new WxaGetCategory();
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));
        if(empty($response['code'])) {
            return $response['errmsg'];
        }
        return $response['data'];
    }

    /**
     * 删除类目
     * @param array $params
     * @param null $mini_info
     * @return mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException Author: fudaoji<fdj@kuryun.cn>
     */
    static function categoryDel($params = [], $mini_info = null){
        $request = new WxOpenDeleteCategory();
        $request->setFirst($params['first']);
        $request->setSecond($params['second']);
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));
        if(empty($response['code'])){
            return $response['errmsg'];
        }
        return true;
    }

    /**
     * 获取类目
     * @param null $mini_info
     * @return mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function categoryGet($mini_info = null){
        $request = new WxOpenGetCategory();
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));
        if(empty($response['code'])){
            return $response['errmsg'];
        }
        return $response['data']['categories'];
    }

    /**
     * 审核状态
     * @param null $id
     * @return array|mixed
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function auditStatus($id = null){
        $list = [
            1 => '审核中',
            2 => '审核不通过',
            3 => '审核通过'
        ];
        return isset($list[$id]) ? $list[$id] : $list;
    }
}